package com.tjnu.losca.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjnu.losca.core.ResponseVO;
import com.tjnu.losca.pojo.Grade;
import com.tjnu.losca.pojo.Studentbygrade;
import com.tjnu.losca.service.IGradeService;
import com.tjnu.losca.service.IStudentbygradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author losca
 * @since 2021-10-20
 */
@RestController
@RequestMapping("/studentbygrade")
public class StudentbygradeController {
    @Autowired
    private IStudentbygradeService studentbygradeService;
    @Autowired
    private IGradeService gradeService;

    @GetMapping("/del")
    public ResponseVO<Boolean> del(Integer id,Integer gradeId){
        studentbygradeService.removeById(id);
        //更新班级人数
        QueryWrapper<Studentbygrade> wrapper = new QueryWrapper<>();
        wrapper.eq("gradeId",id);
        int count = studentbygradeService.count(wrapper);
        Grade grade = new Grade();
        grade.setId(gradeId);
        grade.setCount(count);
        gradeService.updateById(grade);
        return ResponseVO.success("删除成功",true);
    }



}
